﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArithmeticExpressionCalculator
{
    class CalculatorFacade : IExpressionCalculator
    {
        private readonly IStringPreParse preParse;
        private readonly IIsValid isValid;
        private readonly IExpressionCalculator calculator;
        public CalculatorFacade() : this(new ArithmeticExpressionPreParse(), new ArithmeticExpressionIsValid(),
                                         new ArithmeticExpressionCalculator())
        {
        }
        public CalculatorFacade( IStringPreParse preParse, IIsValid isValid, IExpressionCalculator calculator)
        {
            this.preParse = preParse;
            this.isValid = isValid;
            this.calculator = calculator;
        }
        public double Execute(string str)
        {
            preParse.CallAllMethods(ref str);
            if (isValid.IsValid(str))
                return calculator.Execute(str);
            else throw new ValidatorExeption("Формат строки некорректен");
        }
    }
}
